Combo Boxes and ListBoxes

Combo and list boxes are created by using the following buttons.

Start a program form in Visual Basic and create the following form

 


Since Mr. Orton got a 2000 Black Mustang this year, we will use him for the example.

Each of the headings are labels.

The box called combo1 will allow us to choose once of three Cars. (Ferrari, McLaren and Bentley)

I am going to rename all the objects to appropriate names as shown below in the table

Object Type

Object Name

Object Caption or text

Label

Lbltitle

Honest Ortons' Used Cars

Label

Lblnumpurchased

Number Purchased

Label

Lblcartype

Type of Car

Label

Lblunitprice

Unit Price

Label

Lblsubtotal

Subtotal

Label

Lblfinaltotal

Final Total

Command Button

Cmdclear

Clear

Command Button

Cmdnum

0

Command Button

Cmdconfirm

Confirm

ComboBox

Cmbcartype

Type of Car

List Box

Lstnumpurchased

Notapplicable

List Box

Lstcartype

Notapplicable

List Box

Lstunitprice

Notapplicable

List Box

Lstsubtotal

Notapplicable

 


Step 1 Declaring Variables and Constants

 


Constants keep their value throughout the entire program. They never change.


Step 2 Cmd Num

I'd like this one to increase by one each time I clicked on it.

(Hey I might need a couple Ferrari's)

 


Every time I click the left button the value increases by one.

Every time I click the right button the value decreases by one


Step 3 Getting the Combo Box to have selections you want

Actually you do this one in Form Load


Step 4 Getting the Confirm button to work.

 

 


Notice that to add an item to a list box, we use the additem method.

The three if statements control which car is purchased.

As a class we will look at each line of code together and explain it.


Step 5 The Reset button